home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / xmsif15.zip / XMSTEST.C < prev    next >
C/C++ Source or Header  |  1993-05-10  |  59KB  |  1,327 lines

  1. /***************************************************************************
  2. *   xmstest.c                                                              *
  3. *   MODULE:  XMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.3                                                           *
  6. *   DATE:    05/09/93                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1993 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires xmsif.h, testutil.h, and xmstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, Turbo C 2.0, MSC 6.00A, MSC/C++ 7.0.   *
  12. *                                                                          *
  13. *   Regression test and example for XMSIF.                                 *
  14. *                                                                          *
  15. *   This file is part one of the regression tester and example for XMSIF.  *
  16. *   The other parts are named EMSTEST2.C and EMSTEST3.C. All three parts   *
  17. *   must be compiled and linked together along with the appropriate XMSIF  *
  18. *   library to produce the tester executable. This program compiles under  *
  19. *   tiny, small, medium, compact, large, and huge models.                  *
  20. *                                                                          *
  21. *   To use this tester: in general, just run it. Depending on what XMS     *
  22. *   driver you have, you may need to use the "-q" option. HIMEM.SYS does   *
  23. *   not require this option; QEMM 5.1* does; I don't know about other XMS  *
  24. *   drivers. If you haven't used it and should, or should use it and       *
  25. *   haven't, the tester can detect this and will abort with a message      *
  26. *   suggesting you do the opposite of whatever you did. For more detail on *
  27. *   what this option actually does, see below. The tester produces output  *
  28. *   on stdout. It performs 70+ tests, depending on the exact configuration *
  29. *   of your system, and parts of it run quite fast. If you want to read    *
  30. *   all the output, you should redirect the output to a file (but first    *
  31. *   you should probably run it straight to get an idea of how long it      *
  32. *   takes on your machine). If you just want to see whether the tests all  *
  33. *   pass, just run it -- if a test fails, execution aborts immediately.    *
  34. *                                                                          *
  35. *   Certain types of failure may cause XMSTEST to not deallocate memory    *
  36. *   that it has allocated. This should only occur if the library itself is *
  37. *   malfunctioning (which should never happen to you, only to me!) or if   *
  38. *   you are trying a different compiler or unsupported memory model and    *
  39. *   the compiler and library are therefore not communicating properly. It  *
  40. *   may also happen if you press control-break.                            *
  41. *                                                                          *
  42. *                                                                          *
  43. *   The actions XMSTEST takes may be broken down into two parts: EMB tests *
  44. *   and UMB tests. In the first part, it tests the XMM* functions which    *
  45. *   operate on extended memory blocks (EMBs). In the second part, it tests *
  46. *   the UMB* functions which operate on upper memory blocks (UMBs). Before *
  47. *   doing any of this, it tries to initialize XMSIF, which checks for the  *
  48. *   presence of an XMS driver, and aborts if there isn't one. Then it      *
  49. *   starts the first part, performing various preliminary tests on EMBs.   *
  50. *   If it determines that there isn't a large enough EMB free, it reports  *
  51. *   this and skips the copying function tests (tests of _XMMcopy() and     *
  52. *   _XMMicopy()), otherwise it performs the copying function tests. Then   *
  53. *   it starts the second part by trying to determine whether your system   *
  54. *   has UMBs. If it does not, it reports this fact and skips the rest of   *
  55. *   the UMB tests. If it does, it performs the rest of the UMB tests. If   *
  56. *   you see a message about "another broken system", that means that your  *
  57. *   XMS driver's support of UMBs is somewhat flaky, and the workarounds    *
  58. *   already built into XMSIF were unable to cover the problem. In this     *
  59. *   case, it will perform the rest of the UMB tests but is unable to check *
  60. *   that the functions actually did anything -- i.e. it can check the      *
  61. *   return code from the function, but cannot independently verify via     *
  62. *   other functions that the desired effect was actually achieved. See the *
  63. *   XMSIF documentation for a description of problems seen in the UMB      *
  64. *   support of various XMS drivers.                                        *
  65. *                                                                          *
  66. *   The "-q" option covers for some unusual behavior observed in QEMM      *
  67. *   5.1x which may also occur in other XMS drivers which provide EMS       *
  68. *   services as well. In QEMM's case, when extended memory is allocated,   *
  69. *   the total amount of XMS still available is decreased by the allocation *
  70. *   size rounded up to the nearest _16K_ (the EMS page size) instead of to *
  71. *   the nearest 1K (the XMS minimum allocation unit). HIMEM.SYS does not   *
  72. *   display this behavior. The "-q" option tells XMSTEST to expect a drop  *
  73. *   of a multiple of 16K after an allocation instead of a multiple of 1K.  *
  74. *   While XMSTEST can easily detect the difference, this option was added  *
  75. *   so that XMSTEST would know which multiple was expected and could       *
  76. *   detect incorrect drops more reliably.                                  *
  77. *                                                                          *
  78. *   The "-w" option covers for some different unusual behavior observed    *
  79. *   in DOS windows running under MS Windows 3.1 (it is not known whether   *
  80. *   Windows 3.0 does the same thing). In this case, when extended memory   *
  81. *   is allocated, the total amount of XMS still available is decreased by  *
  82. *   the allocation size rounded up to the nearest _4K_ (the 803/486 memory *
  83. *   management page size). The "-w" option tells XMSTEST to expect a drop  *
  84. *   of a multiple of 4K after an allocation instead of a multiple of 1K.   *
  85. *   While XMSTEST can easily detect the difference, this option was added  *
  86. *   so that XMSTEST would know which multiple was expected and could       *
  87. *   detect incorrect drops more reliably.                                  *
  88. *                                                                          *
  89. *   The "-3" option indicates that XMSTEST is running on a 386 or better   *
  90. *   and hence can test the XMMraw3() function safely (if the XMS version   *
  91. *   is 3.0 or better).                                                     *
  92. *                                                                          *
  93. *                                                                          *
  94. *   Turbo C and older versions of Turbo C++ do not have the _fmemcmp() and *
  95. *   _fmemset() functions; I don't know about older versions of MSC. If     *
  96. *   your compiler does not have these functions, define the symbol         *
  97. *   NO_FFUNC and functions in this file will be used instead.              *
  98. *                                                                          *
  99. ***************************************************************************/
  100.  
  101. /*
  102. ** system includes <>
  103. */
  104.  
  105. #include <stdio.h>
  106. #include <stdlib.h>
  107. #include <dos.h>
  108. #include <string.h>
  109. #include <ctype.h>
  110.  
  111.  
  112. /*
  113. ** custom includes ""
  114. */
  115.  
  116. #include "xmsif.h"
  117. #include "xmstest.h"
  118.  
  119. #include "testutil.h"
  120.  
  121. /*
  122. ** local #defines
  123. */
  124.  
  125. /*
  126. ** misc: copyright strings, version macros, etc.
  127. */
  128.  
  129. /*
  130. ** typedefs
  131. */
  132.  
  133. /*
  134. ** global variables
  135. */
  136.  
  137. int testno = 1;                     /* number of test currently being done  */
  138. char *gblmsg = "";                  /* msg to be printed in test header     */
  139.  
  140. int qflag = 0;                      /* running QEMM or not?                 */
  141. int wflag = 0;                      /* running under Windows or not?        */
  142. int on386 = 0;                      /* running on a 386+ or not?            */
  143.  
  144.  
  145. /*
  146. ** static globals
  147. */
  148.  
  149. /*
  150. ** function prototypes
  151. */
  152.  
  153. /*
  154. ** functions
  155. */
  156.  
  157.  
  158. /***************************************************************************
  159. *   FUNCTION: MAIN                                                         *
  160. *                                                                          *
  161. *   DESCRIPTION:                                                           *
  162. *                                                                          *
  163. *       The master function.                                               *
  164. *                                                                          *
  165. *   ENTRY:                                                                 *
  166. *                                                                          *
  167. *       None.                                                              *
  168. *                                                                          *
  169. *   EXIT:                                                                  *
  170. *                                                                          *
  171. *       Void.                                                              *
  172. *                                                                          *
  173. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  174. *                                                                          *
  175. ***************************************************************************/
  176. main(int argc, char *argv[])
  177. {
  178.     int status;                     /* return status from library functions */
  179.     unsigned int version;
  180.     int i;
  181.  
  182.     for (i = 1; i < argc; i++)
  183.     {
  184.         if ((argv[i][0] == '-') || (argv[i][0] == '/'))
  185.         {
  186.             if (toupper(argv[i][1]) == 'Q')
  187.             {
  188.                 qflag = 1;
  189.             }
  190.             else if (toupper(argv[i][1]) == 'W')
  191.             {
  192.                 wflag = 1;
  193.             }
  194.             else if (argv[i][1] == '3')
  195.             {
  196.                 on386 = 1;
  197.             }
  198.             else
  199.             {
  200.                 printf("Usage: XMSTEST [-wq3]\n");
  201.                 exit(1);
  202.             }
  203.         }
  204.         else
  205.         {
  206.             printf("Usage: XMSTEST [-wq3]\n");
  207.             exit(1);
  208.         }
  209.     }
  210.  
  211.     /* set banner */
  212.     gblmsg = "  PRELIMINARY EMB TESTS";
  213.  
  214.     /*
  215.     ** check initialization test
  216.     */
  217.     TESTHEADER();
  218.     printf("Making a call to XMMgetversion() before calling XMMlibinit().\n");
  219.     printf("The call should fail.\n");
  220.     XMMgetversion();
  221.     nofailcheck("XMMgetversion()", (int) _XMMerror, (void far *) NULL, 0, 0);
  222.     weirdcodechk("XMMgetversion()", XMM_NOINIT, (void far *) NULL, 0, 0);
  223.     TESTTAILER();
  224.  
  225.  
  226.     /*
  227.     ** initialize XMSIF
  228.     */
  229.     TESTHEADER();
  230.     printf("Calling XMMlibinit().\n");
  231.     printf("Should succeed if Extended Memory Manager is present.\n");
  232.     status = XMMlibinit();
  233.     switch (status)
  234.     {
  235.         case XMMOOPS:
  236.             printf("XMMlibinit() failed, code 0x%X.\n",
  237.                                                     (unsigned int) _XMMerror);
  238.             exit(3);
  239.             break;
  240.  
  241.         case NOXMM:
  242.             printf("XMMlibinit() did not find an Extended Memory Manager.\n");
  243.             exit(3);
  244.             break;
  245.  
  246.         case 0:
  247.             printf("XMMlibinit() returned OK.\n");
  248.             weirdcodechk("XMMlibinit()", 0, (void far *) NULL, 0, 0);
  249.             break;
  250.  
  251.         default:
  252.             printf("XMMlibinit() returned strange value %d.\n", status);
  253.             exit(3);
  254.             break;
  255.     }
  256.     TESTTAILER();
  257.  
  258.  
  259.     /*
  260.     ** test version call
  261.     */
  262.     TESTHEADER();
  263.     printf("Testing XMMgetversion().\n");
  264.     printf("Results should match value in _XMMversion.\n");
  265.     version = XMMgetversion();
  266.     weirdcodechk("XMMgetversion()", 0, (void far *) NULL, 0, 0);
  267.     if (version != (int) _XMMversion)
  268.     {
  269.         printf("XMMgetversion() [0x%X] and _XMMversion [0x%X] differ.\n",
  270.                                           version, (unsigned int) _XMMversion);
  271.         exit(3);
  272.     }
  273.     printf("XMS version %d.%02d.\n", ((version >> 8) & 0xFF), (version & 0xFF));
  274.     TESTTAILER();
  275.  
  276.  
  277.     /*
  278.     ** test allocation functions
  279.     */
  280.     if (do_alloc_tests(1L) == 0)
  281.     {
  282.         do_alloc_tests(16384L);
  283.         do_alloc_tests(81111L);
  284.         do_alloc_tests(0L);
  285.  
  286.         /*
  287.         ** test rawcall interface
  288.         */
  289.         do_rawcall_tests();
  290.  
  291.         /*
  292.         ** test copies
  293.         */
  294.         do_copy_tests();
  295.     }
  296.  
  297.     /*
  298.     ** test UMB functions (if possible)
  299.     */
  300.     do_UMB_tests();
  301.  
  302.     /* end and cleanup */
  303.     printf(">>>END\n");
  304.     printf("All tests succeeded.\n");
  305.  
  306.     exit(0);
  307. } /* end of main() */
  308.  
  309.  
  310. /***************************************************************************
  311. *   FUNCTION: DO_ALLOC_TESTS                                               *
  312. *                                                                          *
  313. *   DESCRIPTION:                                                           *
  314. *                                                                          *
  315. *       This function tests XMSIF calls XMMcoreleft(), XMMallcoreleft(),   *
  316. *       XMMalloc(), XMMrealloc(), and XMMfree().                           *                *
  317. *                                                                          *
  318. *   ENTRY:                                                                 *
  319. *                                                                          *
  320. *       bytes - number of bytes of XMS to try to allocate.                 *
  321. *                                                                          *
  322. *   EXIT:                                                                  *
  323. *                                                                          *
  324. *       Void.                                                              *
  325. *                                                                          *
  326. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  327. *                                                                          *
  328. ***************************************************************************/
  329. int do_alloc_tests(unsigned long bytes)
  330. {
  331.     unsigned long xmsfreeorig, xmsfreenow;
  332.     unsigned long xmsallfreeorig, xmsallfreenow;
  333.     unsigned long klen, mmupagelen, emspagelen;
  334.     unsigned long expected;
  335.     int handle;
  336.     long diff = ((bytes > HALFLEN) ? -20000 : 20000);
  337.  
  338.     /* get bytes value rounded up to nearest K */
  339.     klen = ((bytes + 1023L) & 0xFFFFFC00);
  340.     /* get bytes value rounded up to nearest 4K */
  341.     mmupagelen = ((bytes + 4095L) & 0xFFFFF000);
  342.     /* get bytes value rounded up to nearest 16K */
  343.     emspagelen = ((bytes + 16383L) & 0xFFFFC000);
  344.  
  345.     /* determine expected length */
  346.     if (qflag != 0)
  347.     {
  348.         expected = emspagelen;
  349.     }
  350.     else if (wflag != 0)
  351.     {
  352.         expected = mmupagelen;
  353.     }
  354.     else
  355.     {
  356.         expected = klen;
  357.     }
  358.  
  359.     /* test coreleft */
  360.     TESTHEADER();
  361.     printf("Testing XMMcoreleft().\n");
  362.     printf("Result should be multiple of 1024.\n");
  363.     xmsfreeorig = test_XMMcoreleft();
  364.     printf("XMMcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  365.            xmsfreeorig, (xmsfreeorig / 1024L));
  366.     TESTTAILER();
  367.  
  368.     /* test allcoreleft */
  369.     TESTHEADER();
  370.     printf("Testing XMMallcoreleft().\n");
  371.     printf("Result should be multiple of 1024 and >= XMMcoreleft().\n");
  372.     xmsallfreeorig = test_XMMallcoreleft();
  373.     if (xmsallfreeorig >= xmsfreeorig)
  374.     {
  375.         printf("XMMallcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  376.                xmsallfreeorig, (xmsallfreeorig / 1024L));
  377.     }
  378.     else
  379.     {
  380.         printf("XMMallcoreleft() returned low value %lu.\n", xmsallfreeorig);
  381.         exit(3);
  382.     }
  383.  
  384.     /* make sure enough free */
  385.     if (xmsallfreeorig < MINFREE)
  386.     {
  387.         printf("Insufficient free XMS to perform all tests. Aborting EMB tests.\n");
  388.         return 1;
  389.     }
  390.     /* enough free, but is it unfragmented enough to be useable? */
  391.     if (xmsfreeorig < MINFREE)
  392.     {
  393.         /* largest block isn't big enough -- can't finish tests */
  394.         printf("XMS too fragmented to perform all tests. Aborting EMB tests.\n");
  395.         return 1;
  396.     }
  397.  
  398.     /* test allocation */
  399.     TESTHEADER();
  400.     printf("Testing XMMalloc(%lu).\n", bytes);
  401.     printf("Should succeed. Free XMS should drop by %lu bytes (%luK).\n",
  402.            expected, (expected / 1024L));
  403.     handle = test_XMMalloc(bytes);
  404.     printf("XMMalloc() returned OK.\n");
  405.     xmsfreenow = test_XMMcoreleft();
  406.     printf("XMMcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  407.            xmsfreenow, (xmsfreenow / 1024L));
  408.     xmsallfreenow = test_XMMallcoreleft();
  409.     printf("XMMallcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  410.            xmsallfreenow, (xmsallfreenow / 1024L));
  411.     if ((xmsallfreeorig - xmsallfreenow) != expected)
  412.     {
  413.         printf("XMMalloc(%lu) caused total free to drop from %lu to %lu.\n",
  414.                bytes, xmsallfreeorig, xmsallfreenow);
  415.         if ((xmsallfreeorig - xmsallfreenow) == emspagelen)
  416.         {
  417.             if (emspagelen == mmupagelen)
  418.             {
  419.                 printf("Try using the -q or -w switches.\n");
  420.             }
  421.             else
  422.             {
  423.                 printf("Try using the -q switch.\n");
  424.             }
  425.         }
  426.         else if ((xmsallfreeorig - xmsallfreenow) == mmupagelen)
  427.         {
  428.             printf("Try using the -w switch.\n");
  429.         }
  430.         else if ((xmsallfreeorig - xmsallfreenow) == klen)
  431.         {
  432.             printf("Try not using the -%c switch.\n",
  433.                    ((qflag != 0) ? 'q' : 'w'));
  434.         }
  435.         XMMfree(handle);
  436.         exit(3);
  437.     }
  438.     TESTTAILER();
  439.  
  440.     /* get realloc value rounded up to nearest K */
  441.     klen = ((bytes + diff + 1023L) & 0xFFFFFC00);
  442.     /* get realloc value rounded up to nearest 4K */
  443.     mmupagelen = ((bytes + diff + 4095L) & 0xFFFFF000);
  444.     /* get realloc value rounded up to nearest 16K */
  445.     emspagelen = ((bytes + diff + 16383L) & 0xFFFFC000);
  446.  
  447.     /* determine expected value */
  448.     if (qflag != 0)
  449.     {
  450.         expected = emspagelen;
  451.     }
  452.     else if (wflag != 0)
  453.     {
  454.         expected = mmupagelen;
  455.     }
  456.     else
  457.     {
  458.         expected = klen;
  459.     }
  460.  
  461.     /* test reallocation */
  462.     TESTHEADER();
  463.     printf("Testing XMMrealloc(%lu).\n", bytes + diff);
  464.     printf("Should succeed. Free XMS should now be %lu bytes (%luK) below original.\n",
  465.            expected, (expected / 1024L));
  466.     handle = test_XMMrealloc(handle, bytes + diff);
  467.     printf("XMMrealloc() returned OK.\n");
  468.     xmsfreenow = test_XMMcoreleft();
  469.     printf("XMMcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  470.            xmsfreenow, (xmsfreenow / 1024L));
  471.     xmsallfreenow = test_XMMallcoreleft();
  472.     printf("XMMallcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  473.            xmsallfreenow, (xmsallfreenow / 1024L));
  474.     if ((xmsallfreeorig - xmsallfreenow) != expected)
  475.     {
  476.         printf("XMMrealloc(%lu) caused total free to be %lu.\n",
  477.                bytes, xmsallfreenow);
  478.         if ((xmsallfreeorig - xmsallfreenow) == emspagelen)
  479.         {
  480.             if (emspagelen == mmupagelen)
  481.             {
  482.                 printf("Try using the -q or -w switches.\n");
  483.             }
  484.             else
  485.             {
  486.                 printf("Try using the -q switch.\n");
  487.             }
  488.         }
  489.         else if ((xmsallfreeorig - xmsallfreenow) == mmupagelen)
  490.         {
  491.             printf("Try using the -w switch.\n");
  492.         }
  493.         else if ((xmsallfreeorig - xmsallfreenow) == klen)
  494.         {
  495.             printf("Try not using the -%c switch.\n",
  496.                    ((qflag != 0) ? 'q' : 'w'));
  497.         }
  498.         XMMfree(handle);
  499.         exit(3);
  500.     }
  501.     TESTTAILER();
  502.  
  503.     /* test free */
  504.     TESTHEADER();
  505.     printf("Testing XMMfree() on handle returned by XMMalloc().\n");
  506.     printf("Should succeed. Free XMS should increase by %lu bytes (%luK).\n",
  507.            expected, (expected / 1024L));
  508.     test_XMMfree(handle);
  509.     printf("XMMfree() returned OK.\n");
  510.     xmsfreenow = test_XMMcoreleft();
  511.     printf("XMMcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  512.            xmsfreenow, (xmsfreenow / 1024L));
  513.     xmsallfreenow = test_XMMallcoreleft();
  514.     printf("XMMallcoreleft() returned OK, shows %lu bytes (%luK) free.\n",
  515.            xmsallfreenow, (xmsallfreenow / 1024L));
  516.     if (xmsallfreenow != xmsallfreeorig)
  517.     {
  518.         printf("Freeing handle returned by XMMalloc() did not restore\n");
  519.         printf("   total free XMS count -- was %lu originally, now %lu.\n",
  520.                xmsallfreeorig, xmsallfreenow);
  521.         exit(3);
  522.     }
  523.     TESTTAILER();
  524.  
  525.     return 0;
  526. } /* end of do_alloc_tests() */
  527.  
  528.  
  529. /***************************************************************************
  530. *   FUNCTION: DO_RAWCALL_TESTS                                             *
  531. *                                                                          *
  532. *   DESCRIPTION:                                                           *
  533. *                                                                          *
  534. *       This function tests the XMSIF calls XMMrawcall() and XMMraw3().    *
  535. *                                                                          *
  536. *   ENTRY:                                                                 *
  537. *                                                                          *
  538. *       Void.                                                              *
  539. *                                                                          *
  540. *   EXIT:                                                                  *
  541. *                                                                          *
  542. *       Void.                                                              *
  543. *                                                                          *
  544. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  545. *                                                                          *
  546. ***************************************************************************/
  547. void do_rawcall_tests()
  548. {
  549.     unsigned long xmsfree, xmsallfree;
  550.     struct XMMregs r;
  551.     int status;
  552.  
  553.     /* first, get something to check against */
  554.     xmsfree = test_XMMcoreleft();
  555.     xmsallfree = test_XMMallcoreleft();
  556.     printf("XMMcoreleft: %lu bytes (%luK)  XMMallcoreleft: %lu bytes (%luK)\n",
  557.                  xmsfree, (xmsfree / 1024L), xmsallfree, (xmsallfree / 1024L));
  558.  
  559.     TESTHEADER();
  560.     printf("Testing XMMrawcall() against XMMcoreleft()/XMMallcoreleft().\n");
  561.     printf("Should succeed.\n");
  562.     r.regAX = 0x0800;
  563.     status = XMMrawcall(&r);
  564.     TRIPLECHECK("XMMrawcall()", status, 0, (void far *) NULL, 0, 0);
  565.     if ((r.regAX != (xmsfree / 1024L)) || (r.regDX != (xmsallfree / 1024L)))
  566.     {
  567.         printf("XMMrawcall() returned %uK and %uK.\n", r.regAX, r.regDX);
  568.         exit(3);
  569.     }
  570.     TESTTAILER();
  571.  
  572.     if (on386 != 0)
  573.     {
  574.         struct XMMbigregs rr;
  575.  
  576.         TESTHEADER();
  577.         printf("Testing XMMraw3() against XMMcoreleft()/XMMallcoreleft().\n");
  578.         if (_XMMversion >= 0x0300)
  579.         {
  580.             printf("Should succeed.\n");
  581.         }
  582.         else
  583.         {
  584.             printf("Should fail.\n");
  585.         }
  586.         rr.regEAX = 0x00008800;
  587.         XMMraw3(&rr);
  588.         if (_XMMversion >= 0x0300)
  589.         {
  590.             weirdcodechk("XMMraw3()", 0, (void far *) NULL, 0, 0);
  591.             if ((rr.regEAX < (xmsfree / 1024L)) ||
  592.                 (rr.regEDX < (xmsallfree / 1024L)))
  593.             {
  594.                 printf("XMMraw3() returned %luK and %luK.\n", rr.regEAX,
  595.                        rr.regEDX);
  596.                 exit(3);
  597.             }
  598.         }
  599.         else if (_XMMerror != XMM_BADVERS)
  600.         {
  601.             printf("XMMraw3() returned unexpected code 0x%X.\n",
  602.                    (unsigned int) _XMMerror);
  603.             exit(3);
  604.         }
  605.         TESTTAILER();
  606.     }
  607.  
  608.     return;
  609. } /* end of do_rawcall_tests() */
  610.  
  611.  
  612. /***************************************************************************
  613. *   FUNCTION: DO_NCOPY1_TESTS                                              *
  614. *                                                                          *
  615. *   DESCRIPTION:                                                           *
  616. *                                                                          *
  617. *       Tests normal copy functions (_XMMcopy() and macros).               *
  618. *                                                                          *
  619. *   ENTRY:                                                                 *
  620. *                                                                          *
  621. *       None.                                                              *
  622. *                                                                          *
  623. *   EXIT:                                                                  *
  624. *                                                                          *
  625. *       Void.                                                              *
  626. *                                                                          *
  627. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  628. *                                                                          *
  629. ***************************************************************************/
  630. void do_ncopy1_tests(void)
  631. {
  632.     int handle = 0;  /* dummy, to make some macros happy */
  633.     unsigned char far *realbuf;
  634.     unsigned char far *guard1, far *guard2, far *guard3;
  635.     unsigned char far *testbuf;
  636.     unsigned char far *testbuf2;
  637.     int status;
  638.  
  639.     /* allocate a conventional memory buffer */
  640.     realbuf = (unsigned char far *) LMALLOC((MINFREE/1024L) + 3);
  641.     if (realbuf == (unsigned char far *) NULL)
  642.     {
  643.         printf("Can't allocate conventional buffer. Aborting.\n");
  644.         exit(3);
  645.     }
  646.  
  647.     /*
  648.     ** Since we can't access EMBs directly, the only way we have of getting
  649.     ** data there is via the copy functions, which we're trying to test. So
  650.     ** the first round of tests will copy data from one half of the
  651.     ** conventional memory to the other, something which we can verify
  652.     ** directly.
  653.     **
  654.     ** Since _XMMcopy is symmetrical, we only need to give one direction
  655.     ** a real workout.
  656.     */
  657.     guard1 = realbuf;
  658.     FMEMSET(guard1, GUARDVAL, 1024);
  659.     testbuf = (unsigned char far *) normptr(guard1 + 1024);
  660.     guard2 = (unsigned char far *) normptr(testbuf + HALFLEN);
  661.     FMEMSET(guard2, GUARDVAL, 1024);
  662.     testbuf2 = (unsigned char far *) normptr(guard2 + 1024);
  663.     guard3 = (unsigned char far *) normptr(testbuf2 + HALFLEN);
  664.     FMEMSET(guard3, GUARDVAL, 1024);
  665.     gblmsg = "  COPY TESTS CONVENTIONAL-CONVENTIONAL";
  666.  
  667.     /* fill first buffer with incrementing words */
  668.     farincwordfill(testbuf, HALFLEN, 0);
  669.     /* fill second buffer with zero */
  670.     FMEMSET(testbuf2, 0, HALFLEN);
  671.  
  672.     /* try an even-length copy from offset 0 to offset 0 */
  673.     TESTHEADER();
  674.     printf("_XMMcopy(): even-length copy from offset 0 to offset 0.\n");
  675.     printf("Should succeed.\n");
  676.     status = _XMMcopy(50, 0, (unsigned long) testbuf, 0,
  677.                                                      (unsigned long) testbuf2);
  678.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  679.     GUARDCHECK(0);
  680.     SRCWORDCHECK(testbuf, HALFLEN);
  681.     CPYWORDCHECK(testbuf2, 50);
  682.     ZEROCHECK((testbuf2 + 50), (HALFLEN - 50));
  683.     TESTTAILER();
  684.  
  685.     /* restore destination pattern */
  686.     FMEMSET(testbuf2, 0, HALFLEN);
  687.  
  688.     /* try an even-length copy from offset 0 to arbitrary offset */
  689.     TESTHEADER();
  690.     printf("_XMMcopy(): even-length copy from offset 0 to arbitrary offset.\n");
  691.     printf("Should succeed.\n");
  692.     status = _XMMcopy(50, 0, (unsigned long) testbuf, 0,
  693.                                               (unsigned long)(testbuf2 + 477));
  694.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  695.     GUARDCHECK(0);
  696.     SRCWORDCHECK(testbuf, HALFLEN);
  697.     ZEROCHECK(testbuf2, 477);
  698.     MEMCMP(testbuf, (testbuf2 + 477), 50);
  699.     ZEROCHECK((testbuf2 + 477 + 50), ((HALFLEN - 477) - 50));
  700.     TESTTAILER();
  701.  
  702.     /* restore destination pattern */
  703.     FMEMSET(testbuf2, 0, HALFLEN);
  704.  
  705.     /* try an even-length copy from offset 0 to just before the end */
  706.     TESTHEADER();
  707.     printf("_XMMcopy(): even-length copy from offset 0 to just before end.\n");
  708.     printf("Should succeed.\n");
  709.     status = _XMMcopy(50, 0, (unsigned long) testbuf, 0,
  710.                                      (unsigned long)(testbuf2 + HALFLEN - 50));
  711.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  712.     GUARDCHECK(0);
  713.     SRCWORDCHECK(testbuf, HALFLEN);
  714.     ZEROCHECK(testbuf2, (HALFLEN - 50));
  715.     CPYWORDCHECK((testbuf2 + HALFLEN - 50), 50);
  716.     TESTTAILER();
  717.  
  718.     /* restore destination pattern */
  719.     FMEMSET(testbuf2, 0, HALFLEN);
  720.  
  721.     /* try an even-length copy from arbitrary offset to arbitrary offset */
  722.     TESTHEADER();
  723.     printf("_XMMcopy(): even-length copy from arbitrary offset to ");
  724.     printf("arbitrary offset.\nShould succeed.");
  725.     status = _XMMcopy(50, 0, (unsigned long)(testbuf + 384), 0,
  726.                                            (unsigned long)(testbuf2 + 33333U));
  727.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  728.     GUARDCHECK(0);
  729.     SRCWORDCHECK(testbuf, HALFLEN);
  730.     ZEROCHECK(testbuf2, 33333U);
  731.     MEMCMP((testbuf + 384), (testbuf2 + 33333U), 50);
  732.     ZEROCHECK((testbuf2 + 33333U + 50), ((HALFLEN - 33333U) - 50));
  733.     TESTTAILER();
  734.  
  735.     /* restore destination pattern */
  736.     FMEMSET(testbuf2, 0, HALFLEN);
  737.  
  738.     /* try an even-length copy from just before the end to arbitrary offset */
  739.     TESTHEADER();
  740.     printf("_XMMcopy(): even-length copy from just before end to arbitrary.\n");
  741.     printf("Should succeed.\n");
  742.     status = _XMMcopy(50, 0, (unsigned long)(testbuf + HALFLEN - 50), 0,
  743.                                              (unsigned long)(testbuf2 + 7676));
  744.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  745.     GUARDCHECK(0);
  746.     SRCWORDCHECK(testbuf, HALFLEN);
  747.     ZEROCHECK(testbuf2, 7676);
  748.     MEMCMP((testbuf + HALFLEN - 50), (testbuf2 + 7676), 50);
  749.     ZEROCHECK((testbuf2 + 7676 + 50), ((HALFLEN - 7676) - 50));
  750.     TESTTAILER();
  751.  
  752.     /* restore destination pattern */
  753.     FMEMSET(testbuf2, 0, HALFLEN);
  754.  
  755.  
  756.     /* try an odd-length copy from offset 0 to offset 0 */
  757.     TESTHEADER();
  758.     printf("_XMMcopy(): odd-length copy from offset 0 to offset 0.\n");
  759.     printf("Should succeed.\n");
  760.     status = _XMMcopy(111, 0, (unsigned long) testbuf, 0,
  761.                                                      (unsigned long) testbuf2);
  762.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  763.     GUARDCHECK(0);
  764.     SRCWORDCHECK(testbuf, HALFLEN);
  765.     MEMCMP(testbuf, testbuf2, 111);
  766.     ZEROCHECK((testbuf2 + 111), (HALFLEN - 111));
  767.     TESTTAILER();
  768.  
  769.     /* restore destination pattern */
  770.     FMEMSET(testbuf2, 0, HALFLEN);
  771.  
  772.     /* try an odd-length copy from offset 0 to offset misc */
  773.     TESTHEADER();
  774.     printf("_XMMcopy(): odd-length copy from offset 0 to arbitrary offset.\n");
  775.     printf("Should succeed.\n");
  776.     status = _XMMcopy(111, 0, (unsigned long) testbuf, 0,
  777.                                               (unsigned long)(testbuf2 + 477));
  778.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  779.     GUARDCHECK(0);
  780.     SRCWORDCHECK(testbuf, HALFLEN);
  781.     ZEROCHECK(testbuf2, 477);
  782.     MEMCMP(testbuf, (testbuf2 + 477), 111);
  783.     ZEROCHECK((testbuf2 + 477 + 111), ((HALFLEN - 477) - 111));
  784.     TESTTAILER();
  785.  
  786.     /* restore destination pattern */
  787.     FMEMSET(testbuf2, 0, HALFLEN);
  788.  
  789.     /* try an odd-length copy from offset 0 to just before the end */
  790.     TESTHEADER();
  791.     printf("_XMMcopy(): odd-length copy from offset 0 to just before end.\n");
  792.     printf("Should succeed.\n");
  793.     status = _XMMcopy(111, 0, (unsigned long) testbuf, 0,
  794.                                     (unsigned long)(testbuf2 + HALFLEN - 111));
  795.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  796.     GUARDCHECK(0);
  797.     SRCWORDCHECK(testbuf, HALFLEN);
  798.     ZEROCHECK(testbuf2, (HALFLEN - 111));
  799.     MEMCMP(testbuf, (testbuf2 + HALFLEN - 111), 111);
  800.     TESTTAILER();
  801.  
  802.     /* restore destination pattern */
  803.     FMEMSET(testbuf2, 0, HALFLEN);
  804.  
  805.     /* try an odd-length copy from arbitrary offset to arbitrary offset */
  806.     TESTHEADER();
  807.     printf("_XMMcopy(): odd-length copy from arbitrary offset to ");
  808.     printf("arbitrary offset.\nShould succeed.\n");
  809.     status = _XMMcopy(111, 0, (unsigned long)(testbuf + 384), 0,
  810.                                            (unsigned long)(testbuf2 + 33333U));
  811.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  812.     GUARDCHECK(0);
  813.     SRCWORDCHECK(testbuf, HALFLEN);
  814.     ZEROCHECK(testbuf2, 33333U);
  815.     MEMCMP((testbuf + 384), (testbuf2 + 33333U), 111);
  816.     ZEROCHECK((testbuf2 + 33333U + 111), ((HALFLEN - 33333U) - 111));
  817.     TESTTAILER();
  818.  
  819.     /* restore destination pattern */
  820.     FMEMSET(testbuf2, 0, HALFLEN);
  821.  
  822.     /* try an odd-length copy from just before the end to arbitrary offset */
  823.     TESTHEADER();
  824.     printf("_XMMcopy(): odd-length copy from just before end to arbitrary.\n");
  825.     printf("Should succeed.\n");
  826.     status = _XMMcopy(111, 0, (unsigned long)(testbuf + HALFLEN - 111), 0,
  827.                                              (unsigned long)(testbuf2 + 7676));
  828.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  829.     GUARDCHECK(0);
  830.     SRCWORDCHECK(testbuf, HALFLEN);
  831.     ZEROCHECK(testbuf2, 7676);
  832.     MEMCMP((testbuf + HALFLEN - 111), (testbuf2 + 7676), 111);
  833.     ZEROCHECK((testbuf2 + 7676 + 111), ((HALFLEN - 7676) - 111));
  834.     TESTTAILER();
  835.  
  836.     /* restore destination pattern */
  837.     FMEMSET(testbuf2, 0, HALFLEN);
  838.  
  839.  
  840.     /* try a one-byte copy from offset 0 to offset 0 */
  841.     TESTHEADER();
  842.     printf("_XMMcopy(): one-byte copy from offset 0 to offset 0.\n");
  843.     printf("Should succeed.\n");
  844.     status = _XMMcopy(1, 0, (unsigned long) testbuf, 0,
  845.                                                      (unsigned long) testbuf2);
  846.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  847.     GUARDCHECK(0);
  848.     SRCWORDCHECK(testbuf, HALFLEN);
  849.     MEMCMP(testbuf, testbuf2, 1);
  850.     ZEROCHECK((testbuf2 + 1), (HALFLEN - 1));
  851.     TESTTAILER();
  852.  
  853.     /* restore destination pattern */
  854.     FMEMSET(testbuf2, 0, HALFLEN);
  855.  
  856.     /* try a one-byte copy from offset 0 to offset misc */
  857.     TESTHEADER();
  858.     printf("_XMMcopy(): one-byte copy from offset 0 to arbitrary offset.\n");
  859.     printf("Should succeed.\n");
  860.     status = _XMMcopy(1, 0, (unsigned long) testbuf, 0,
  861.                                               (unsigned long)(testbuf2 + 477));
  862.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  863.     GUARDCHECK(0);
  864.     SRCWORDCHECK(testbuf, HALFLEN);
  865.     ZEROCHECK(testbuf2, 477);
  866.     MEMCMP(testbuf, (testbuf2 + 477), 1);
  867.     ZEROCHECK((testbuf2 + 477 + 1), ((HALFLEN - 477) - 1));
  868.     TESTTAILER();
  869.  
  870.     /* restore destination pattern */
  871.     FMEMSET(testbuf2, 0, HALFLEN);
  872.  
  873.     /* try a one-byte copy from offset 0 to just before the end */
  874.     TESTHEADER();
  875.     printf("_XMMcopy(): one-byte copy from offset 0 to just before end.\n");
  876.     printf("Should succeed.\n");
  877.     status = _XMMcopy(1, 0, (unsigned long) testbuf, 0,
  878.                                       (unsigned long)(testbuf2 + HALFLEN - 1));
  879.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  880.     GUARDCHECK(0);
  881.     SRCWORDCHECK(testbuf, HALFLEN);
  882.     ZEROCHECK(testbuf2, (HALFLEN - 1));
  883.     MEMCMP(testbuf, (testbuf2 + HALFLEN - 1), 1);
  884.     TESTTAILER();
  885.  
  886.     /* restore destination pattern */
  887.     FMEMSET(testbuf2, 0, HALFLEN);
  888.  
  889.     /* try a one-byte copy from arbitrary offset to arbitrary offset */
  890.     TESTHEADER();
  891.     printf("_XMMcopy(): one-byte copy from arbitrary offset to ");
  892.     printf("arbitrary offset.\nShould succeed.");
  893.     status = _XMMcopy(1, 0, (unsigned long)(testbuf + 384), 0,
  894.                                            (unsigned long)(testbuf2 + 33333U));
  895.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  896.     GUARDCHECK(0);
  897.     SRCWORDCHECK(testbuf, HALFLEN);
  898.     ZEROCHECK(testbuf2, 33333U);
  899.     MEMCMP((testbuf + 384), (testbuf2 + 33333U), 1);
  900.     ZEROCHECK((testbuf2 + 33333U + 1), ((HALFLEN - 33333U) - 1));
  901.     TESTTAILER();
  902.  
  903.     /* restore destination pattern */
  904.     FMEMSET(testbuf2, 0, HALFLEN);
  905.  
  906.     /* try a one-byte copy from just before the end to arbitrary offset */
  907.     TESTHEADER();
  908.     printf("_XMMcopy(): one-byte copy from just before end to arbitrary.\n");
  909.     printf("Should succeed.\n");
  910.     status = _XMMcopy(1, 0, (unsigned long)(testbuf + HALFLEN - 1), 0,
  911.                                              (unsigned long)(testbuf2 + 7676));
  912.     TRIPLECHECK("_XMMcopy()", status, 0, (void far *) realbuf, 0, 0);
  913.     GUARDCHECK(0);
  914.     SRCWORDCHECK(testbuf, HALFLEN);
  915.     ZEROCHECK(testbuf2, 7676);
  916.     MEMCMP((testbuf + HALFLEN - 1), (testbuf2 + 7676), 1);
  917.     ZEROCHECK((testbuf2 + 7676 + 1), ((HALFLEN - 7676) - 1));
  918.     TESTTAILER();
  919.  
  920.     /*
  921.     ** Clean up.
  922.     */
  923.     LFREE(realbuf);
  924.  
  925.     return;
  926. } /* end of do_ncopy1_tests() */
  927.  
  928.  
  929. /*
  930. ** The following group of functions {test_XMM*()} are wrapper functions
  931. ** that call the XMSIF function named and perform preliminary checks on
  932. ** the return values. This keeps code size down since the check only has
  933. ** to be coded in one place.
  934. */
  935.  
  936.  
  937. /***************************************************************************
  938. *   FUNCTION: TEST_XMMCORELEFT                                             *
  939. *                                                                          *
  940. *   DESCRIPTION:                                                           *
  941. *                                                                          *
  942. *       This function calls XMSIF function XMMcoreleft() and checks the    *
  943. *       return value to see if it is a multiple of 1024 (the minimum XMS   *
  944. *       allocation unit).                                                  *
  945. *                                                                          *
  946. *   ENTRY:                                                                 *
  947. *                                                                          *
  948. *       Void.                                                              *
  949. *                                                                          *
  950. *   EXIT:                                                                  *
  951. *                                                                          *
  952. *       Returns the value returned by XMMcoreleft().                       *
  953. *                                                                          *
  954. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  955. *                                                                          *
  956. ***************************************************************************/
  957. unsigned long test_XMMcoreleft(void)
  958. {
  959.     unsigned long xmsfree;
  960.  
  961.     /* call XMMcoreleft and check error code */
  962.     xmsfree = XMMcoreleft();
  963.     weirdcodechk("XMMcoreleft()", 0, (void far *) NULL, 0, 0);
  964.  
  965.     /* check if free byte count is multiple of 1024 */
  966.     if ((xmsfree % 1024L) != 0)
  967.     {
  968.         printf("XMMcoreleft() returned strange number %lu.\n", xmsfree);
  969.         exit(3);
  970.     }
  971.  
  972.     return xmsfree;
  973. } /* end of test_XMMcoreleft() */
  974.  
  975.  
  976. /***************************************************************************
  977. *   FUNCTION: TEST_XMMALLCORELEFT                                          *
  978. *                                                                          *
  979. *   DESCRIPTION:                                                           *
  980. *                                                                          *
  981. *       This function calls XMSIF function XMMallcoreleft() and checks     *
  982. *       the return value to see if it is a multiple of 1024 (the minimum   *
  983. *       XMS allocation unit).                                              *
  984. *                                                                          *
  985. *   ENTRY:                                                                 *
  986. *                                                                          *
  987. *       Void.                                                              *
  988. *                                                                          *
  989. *   EXIT:                                                                  *
  990. *                                                                          *
  991. *       Returns the value returned by XMMallcoreleft().                    *
  992. *                                                                          *
  993. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  994. *                                                                          *
  995. ***************************************************************************/
  996. unsigned long test_XMMallcoreleft(void)
  997. {
  998.     unsigned long xmsfree;
  999.  
  1000.     /* call XMMallcoreleft and check error code */
  1001.     xmsfree = XMMallcoreleft();
  1002.     weirdcodechk("XMMallcoreleft()", 0, (void far *) NULL, 0, 0);
  1003.  
  1004.     /* check if free byte count is multiple of 1024 */
  1005.     if ((xmsfree % 1024L) != 0)
  1006.     {
  1007.         printf("XMMallcoreleft() returned strange number %lu.\n", xmsfree);
  1008.         exit(3);
  1009.     }
  1010.  
  1011.     return xmsfree;
  1012. } /* end of test_XMMallcoreleft() */
  1013.  
  1014.  
  1015. /***************************************************************************
  1016. *   FUNCTION: TEST_XMMALLOC                                                *
  1017. *                                                                          *
  1018. *   DESCRIPTION:                                                           *
  1019. *                                                                          *
  1020. *       This function calls XMSIF function XMMalloc() and checks the       *
  1021. *       return codes.                                                      *
  1022. *                                                                          *
  1023. *   ENTRY:                                                                 *
  1024. *                                                                          *
  1025. *       bytes - bytes of XMS to allocate                                   *
  1026. *                                                                          *
  1027. *   EXIT:                                                                  *
  1028. *                                                                          *
  1029. *       Returns the handle returned by XMMalloc().                         *
  1030. *                                                                          *
  1031. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1032. *                                                                          *
  1033. ***************************************************************************/
  1034. int test_XMMalloc(unsigned long bytes)
  1035. {
  1036.     int handle;
  1037.  
  1038.     /* call XMMalloc() and check the return */
  1039.     handle = XMMalloc(bytes);
  1040.     weirdcodechk("XMMalloc()", 0, (void far *) NULL, 0, 0);
  1041.  
  1042.     return handle;
  1043. } /* end of test_XMMalloc() */
  1044.  
  1045.  
  1046. /***************************************************************************
  1047. *   FUNCTION: TEST_XMMREALLOC                                              *
  1048. *                                                                          *
  1049. *   DESCRIPTION:                                                           *
  1050. *                                                                          *
  1051. *       This function calls XMSIF function XMMrealloc() and checks the     *
  1052. *       return codes.                                                      *
  1053. *                                                                          *
  1054. *   ENTRY:                                                                 *
  1055. *                                                                          *
  1056. *       handle - XMS handle to reallocate                                  *
  1057. *       bytes  - new size of XMS block                                     *
  1058. *                                                                          *
  1059. *   EXIT:                                                                  *
  1060. *                                                                          *
  1061. *       Returns the handle returned by XMMrealloc(), which is the same as  *
  1062. *       the argument handle.                                               *
  1063. *                                                                          *
  1064. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1065. *                                                                          *
  1066. ***************************************************************************/
  1067. int test_XMMrealloc(int handle, unsigned long bytes)
  1068. {
  1069.     int newhandle;
  1070.  
  1071.     /* call XMMrealloc() and check the return */
  1072.     newhandle = XMMrealloc(handle, bytes);
  1073.     weirdcodechk("XMMrealloc()", 0, (void far *) NULL, 0, 0);
  1074.     if (newhandle != handle)
  1075.     {
  1076.         printf("Passed handle %d to XMMrealloc(), got handle %d back.\n",
  1077.                handle, newhandle);
  1078.         XMMfree(handle);
  1079.         exit(3);
  1080.     }
  1081.  
  1082.     return newhandle;
  1083. } /* end of test_XMMrealloc() */
  1084.  
  1085.  
  1086. /***************************************************************************
  1087. *   FUNCTION: TEST_XMMFREE                                                 *
  1088. *                                                                          *
  1089. *   DESCRIPTION:                                                           *
  1090. *                                                                          *
  1091. *       This function calls XMSIF function XMMfree() and checks the        *
  1092. *       return codes.                                                      *
  1093. *                                                                          *
  1094. *   ENTRY:                                                                 *
  1095. *                                                                          *
  1096. *       handle - XMS EMB handle to be freed                                *
  1097. *                                                                          *
  1098. *   EXIT:                                                                  *
  1099. *                                                                          *
  1100. *       Void.                                                              *
  1101. *                                                                          *
  1102. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1103. *                                                                          *
  1104. ***************************************************************************/
  1105. void test_XMMfree(int handle)
  1106. {
  1107.     int status;
  1108.  
  1109.     /* call XMMfree() and check the return */
  1110.     status = XMMfree(handle);
  1111.     TRIPLECHECK("XMMfree()", status, 0, (void far *) NULL, 0, 0);
  1112.  
  1113.     return;
  1114. } /* end of test_XMMfree() */
  1115.  
  1116.  
  1117. /*
  1118. ** The following group of functions are used to speed up return checking
  1119. ** and keep code size down, since the return check only has to be coded
  1120. ** in one place. They are used in various macros to further compact and
  1121. ** clarify the code.
  1122. */
  1123.  
  1124. /***************************************************************************
  1125. *   FUNCTION: WEIRDRETCHK                                                  *
  1126. *                                                                          *
  1127. *   DESCRIPTION:                                                           *
  1128. *                                                                          *
  1129. *       This function checks to see if the status value passed to it is    *
  1130. *       either 0 or XMMOOPS, and assumes something has gone wrong if it    *
  1131. *       is not. If something has gone wrong, does some clean up before     *
  1132. *       exiting.                                                           *
  1133. *                                                                          *
  1134. *   ENTRY:                                                                 *
  1135. *                                                                          *
  1136. *       function - name of function which may have goofed                  *
  1137. *       status   - status value to check                                   *
  1138. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1139. *                  freed if NULL.                                          *
  1140. *       tofree2  - XMS handle to be freed on exit. Not freed if 0.         *
  1141. *       tofree2  - another XMS handle to be freed on exit. Not freed if 0. *
  1142. *                                                                          *
  1143. *   EXIT:                                                                  *
  1144. *                                                                          *
  1145. *       Void, or may not return.                                           *
  1146. *                                                                          *
  1147. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1148. *                                                                          *
  1149. ***************************************************************************/
  1150. void weirdretchk(char *function, int status, void far *tofree1, int tofree2,
  1151.                                                                    int tofree3)
  1152. {
  1153.     if ((status != XMMOOPS) && (status != 0))
  1154.     {
  1155.         printf("%s returned weird value %d, code 0x%X.\n", function, status,
  1156.                                                      (unsigned int) _XMMerror);
  1157.         if (tofree1 != (void far *) NULL)
  1158.         {
  1159.             LFREE(tofree1);
  1160.         }
  1161.         if (tofree2 != 0)
  1162.         {
  1163.             XMMfree(tofree2);
  1164.         }
  1165.         if (tofree3 != 0)
  1166.         {
  1167.             XMMfree(tofree3);
  1168.         }
  1169.         exit(3);
  1170.     }
  1171.  
  1172.     return;
  1173. } /* end of weirdretchk() */
  1174.  
  1175.  
  1176. /***************************************************************************
  1177. *   FUNCTION: WEIRDCODECHK                                                 *
  1178. *                                                                          *
  1179. *   DESCRIPTION:                                                           *
  1180. *                                                                          *
  1181. *       This function checks to see if the XMSIF error code value matches  *
  1182. *       the expected value, and assumes something has gone wrong if it     *
  1183. *       does not. If something has gone wrong, does some clean up before   *
  1184. *       exiting.                                                           *
  1185. *                                                                          *
  1186. *   ENTRY:                                                                 *
  1187. *                                                                          *
  1188. *       function - name of function which may have goofed                  *
  1189. *       expected - expected value of _XMMerror                             *
  1190. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1191. *                  freed if NULL.                                          *
  1192. *       tofree2  - XMS handle to be freed on exit. Not freed if 0.         *
  1193. *       tofree2  - another XMS handle to be freed on exit. Not freed if 0. *
  1194. *                                                                          *
  1195. *   EXIT:                                                                  *
  1196. *                                                                          *
  1197. *       Void, or may not return.                                           *
  1198. *                                                                          *
  1199. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1200. *                                                                          *
  1201. ***************************************************************************/
  1202. void weirdcodechk(char *function, int expected, void far *tofree1, int tofree2,
  1203.                                                                    int tofree3)
  1204. {
  1205.     if ((int) _XMMerror != expected)
  1206.     {
  1207.         printf("%s returned unexpected code 0x%X.\n", function,
  1208.                                                      (unsigned int) _XMMerror);
  1209.         if (tofree1 != (void far *) NULL)
  1210.         {
  1211.             LFREE(tofree1);
  1212.         }
  1213.         if (tofree2 != 0)
  1214.         {
  1215.             XMMfree(tofree2);
  1216.         }
  1217.         if (tofree3 != 0)
  1218.         {
  1219.             XMMfree(tofree3);
  1220.         }
  1221.         exit(3);
  1222.     }
  1223.  
  1224.     return;
  1225. } /* end of weirdcodechk() */
  1226.  
  1227.  
  1228. /***************************************************************************
  1229. *   FUNCTION: FAILCHECK                                                    *
  1230. *                                                                          *
  1231. *   DESCRIPTION:                                                           *
  1232. *                                                                          *
  1233. *       This function checks to see if the status value passed to it is    *
  1234. *       XMMOOPS and exits if it is. failcheck() is used when a function    *
  1235. *       is expected to succeed. Does some clean up before exiting.         *
  1236. *                                                                          *
  1237. *   ENTRY:                                                                 *
  1238. *                                                                          *
  1239. *       function - name of function which may have goofed                  *
  1240. *       status   - status value to be checked                              *
  1241. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1242. *                  freed if NULL.                                          *
  1243. *       tofree2  - XMS handle to be freed on exit. Not freed if 0.         *
  1244. *       tofree2  - another XMS handle to be freed on exit. Not freed if 0. *
  1245. *                                                                          *
  1246. *   EXIT:                                                                  *
  1247. *                                                                          *
  1248. *       Void, or may not return.                                           *
  1249. *                                                                          *
  1250. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1251. *                                                                          *
  1252. ***************************************************************************/
  1253. void failcheck(char *function, int status, void far *tofree1, int tofree2,
  1254.                                                                   int tofree3)
  1255. {
  1256.     if (status == XMMOOPS)
  1257.     {
  1258.         printf("%s failed, code 0x%X.\n", function, (unsigned int) _XMMerror);
  1259.         if (tofree1 != (void far *) NULL)
  1260.         {
  1261.             LFREE(tofree1);
  1262.         }
  1263.         if (tofree2 != 0)
  1264.         {
  1265.             XMMfree(tofree2);
  1266.         }
  1267.         if (tofree3 != 0)
  1268.         {
  1269.             XMMfree(tofree3);
  1270.         }
  1271.         exit(3);
  1272.     }
  1273.  
  1274.     return;
  1275. } /* end of failcheck() */
  1276.  
  1277.  
  1278. /***************************************************************************
  1279. *   FUNCTION: NOFAILCHECK                                                  *
  1280. *                                                                          *
  1281. *   DESCRIPTION:                                                           *
  1282. *                                                                          *
  1283. *       This function checks to see if the status value passed to it is    *
  1284. *       0 and exits if it is. nofailcheck() is used when a function is     *
  1285. *       expected to fail. Does some clean up before exiting.               *
  1286. *                                                                          *
  1287. *   ENTRY:                                                                 *
  1288. *                                                                          *
  1289. *       function - name of function which may have goofed                  *
  1290. *       status   - status value to be checked                              *
  1291. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1292. *                  freed if NULL.                                          *
  1293. *       tofree2  - XMS handle to be freed on exit. Not freed if 0.         *
  1294. *       tofree2  - another XMS handle to be freed on exit. Not freed if 0. *
  1295. *                                                                          *
  1296. *   EXIT:                                                                  *
  1297. *                                                                          *
  1298. *       Void, or may not return.                                           *
  1299. *                                                                          *
  1300. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1301. *                                                                          *
  1302. ***************************************************************************/
  1303. void nofailcheck(char *function, int status, void far *tofree1, int tofree2,
  1304.                                                                   int tofree3)
  1305. {
  1306.     if (status == 0)
  1307.     {
  1308.         printf("%s did not fail.\n", function);
  1309.         if (tofree1 != (void far *) NULL)
  1310.         {
  1311.             LFREE(tofree1);
  1312.         }
  1313.         if (tofree2 != 0)
  1314.         {
  1315.             XMMfree(tofree2);
  1316.         }
  1317.         if (tofree3 != 0)
  1318.         {
  1319.             XMMfree(tofree3);
  1320.         }
  1321.         exit(3);
  1322.     }
  1323.  
  1324.     return;
  1325. } /* end of nofailcheck() */
  1326.  
  1327.